package main

import (
	"fmt"
	"math/rand"
)

func main() {
	q1()
	q2()
	q3()
}

func q1() {

	for i := 1; i < 10; i++ {
		for j := 1; j <= i; j++ {
			fmt.Printf("%v%v%v%v%-3d", j, "*", i, "=", i*j)
		}
		fmt.Println()
	}
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
}

func q2() {

	var arr [20]int
	var odd_sum, even_sum int

	for i := 0; i < len(arr); i++ {
		arr[i] = rand.Intn(len(arr)-1) + 1
	}

	for i := 0; i < len(arr)-1; i += 2 {
		odd_sum += arr[i]
	}

	for i := 1; i < len(arr); i += 2 {
		even_sum += arr[i]
	}

	fmt.Printf("20内随机数: %v\n", arr)
	fmt.Println("奇数位之和：", odd_sum)
	fmt.Println("偶数位之和：", even_sum)
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
}

func q3() {

	var i, k int

	fmt.Print("100以内斐波那契数列: ", i, " ")
	for j := 1; j < 100; j += k {
		k += j
		fmt.Print(j, " ")
		if k > 100 {
			break
		}
		fmt.Print(k, " ")
	}
}
